#include "ExpressionValue.h"
#include <iostream>
#include "Exceptions.h"

using namespace std;

ExpressionValue* ExpressionValue::Copy()
{
    switch(this->fType)
    {
        case LongInteger:
            return new ExpressionValue(this->fValue.LongValue);
        case Double:
            return new ExpressionValue(this->fValue.DoubleValue);
        case String:
            // musime zkopirovat string, jinak mame problem
            return new ExpressionValue(new string(*(this->fValue.StringValue))); 
        case Boolean:
            return new ExpressionValue(this->fValue.BoolValue);
        default:
            throw BaseException("ExpressionValue::Copy: nepodporovany typ.");
    }
}

void ExpressionValue::ConstructorBase()
{
    fType = Undefined;
    fRefCount = 0;
}

ExpressionValue::ExpressionValue()
{
    ConstructorBase();
}

ExpressionValue::ExpressionValue(long iLongValue)
{
    ConstructorBase();
    fType = LongInteger;
    fValue.LongValue = iLongValue;
}

ExpressionValue::ExpressionValue(double iDoubleValue)
{
    ConstructorBase();
    fType = Double;
    fValue.DoubleValue = iDoubleValue;
}

ExpressionValue::ExpressionValue(string* iStringValue)
{
    ConstructorBase();
    fType = String;
    fValue.StringValue = iStringValue;
}

ExpressionValue::ExpressionValue(bool iBoolValue)
{
    ConstructorBase();
    fType = Boolean;
    fValue.BoolValue = iBoolValue;
}

ExpressionValue::~ExpressionValue()
{
    if(fType == String)
        delete fValue.StringValue;
}
/*
void ExpressionValue::PrintToStdOut(string iParentName)
{
    switch(fType)
    {
        case LongInteger:   cout << fValue.LongValue << endl;       return;
        case Double:        cout << fValue.DoubleValue << endl;     return;
        case String:        cout << *(fValue.StringValue) << endl;  return;
        case Boolean:       cout << fValue.BoolValue << endl;       return;
    }

    throw BadTypeToPrintException(fType, iParentName);
}*/
